
<?php
// print_r($user);
?>

<ul class="breadcrumb">
  <li><a href="<?php echo $this->webroot;?>">Home</a><span class="divider">/</span></li>
  <li><a href="<?php echo $this->webroot;?>Users/index"><?php echo __("Lista Utenti") ?></a><span class="divider">/</span></li>
  <li class="active"><?php echo __("Modifica Utente"); ?></li>
</ul>

<form action="<?php echo $this->webroot;?>Users/save" method="post" id="form">
	<div class="row-fluid">
		<div class="span3">
	  		<?php if (!empty($user['Attach']['Anagrafica']['foto'])) { ?>
	  			<a href="#" class="thumbnail">
					<img src="<?php echo $this->webroot.$user['Attach']['Anagrafica']['foto']?>" class='img-rounded' />
			    </a>
	  		<?php } else { ?>
					<img src="<?php echo $this->webroot.'img/utente.jpg'?>" style='width: 100px;height: 100px' class='img-rounded' />
	  		<?php } ?>
		</div>
		<div class="span9">
				<div class="tabbable"> <!-- Only required for left/right tabs -->
				  <ul class="nav nav-tabs">
				    <li class="active"><a href="#tab1" data-toggle="tab"><?php echo __("Utente"); ?></a></li>
				    <li><a href="#tab2" data-toggle="tab"><?php echo __("Anagrafica"); ?></a></li>
				  </ul>
				  <div class="tab-content">
				    <div class="tab-pane active" id="tab1">
							    	
						<fieldset>
						    <input type='hidden' name='User[id]' value='<?php echo $user['User']['id'];?>' />
						    <label><?php echo __("Username"); ?></label> <input type="text" name="User[username]" value="<?php echo $user['User']['username'];?>" placeholder="Username" disabled>
						    <label><?php echo __("Email"); ?></label> <input type="text" name="User[email]" value="<?php echo $user['User']['email'];?>" placeholder="Email" >
						    <label><?php echo __("Gruppo"); ?></label>
							<select name='User[group_id]'>
								<option value=''></option>
								<?foreach ($groups as $key => $group) {?>
							  			<option value='<? echo $key?>' <? if($key == $user['User']['group_id']) echo " selected='selected' " ?>  ><? echo $group ?></option>
								<? } ?> 
							</select> 
						    <label><?php echo __("Ultimo accesso"); ?></label> <input type="text" name="User[dt_accesso]" value="<?php echo $user['User']['dt_accesso'];?>" placeholder="" disabled>
						    <label><?php echo __("Scadenza"); ?></label> <input type="text" name="User[dt_scadenza]" value="<?php echo $user['User']['dt_scadenza'];?>" placeholder="" disabled>
						    <label>Stato</label>
							<select name='User[stato]'>
								<?foreach ($stati as $key => $stato) {?>
							  			<option value='<? echo $key?>' <? if($key == $user['User']['stato']) echo " selected='selected' " ?>  ><? echo $stato ?></option>
								<? } ?> 
							</select> 
						</fieldset>
				    </div>
				    <div class="tab-pane" id="tab2">
						<fieldset>
						    <input type='hidden' name='Anagrafica[id]' value='<?php echo $user['Anagrafica']['id'];?>' />
						    <label><?php echo __("Nome"); ?></label> <input type="text" name="Anagrafica[nome]" value="<?php echo $user['Anagrafica']['nome'];?>" placeholder="nome" >
						    <label><?php echo __("Cognome"); ?></label> <input type="text" name="Anagrafica[cognome]" value="<?php echo $user['Anagrafica']['cognome'];?>" placeholder="Cognome" >
						    <label><?echo __("Comune")?></label>
							<select name='Anagrafica[comune_id]' id="comune" style="width: 240px;">
								<option value=''></option>
								<?foreach ($comuni as $comune) {?>
							  			<option data-idprovincia='<?php echo $comune['Comune']['provincia_id']?>' value='<? echo $comune['Comune']['id']?>' <? if($comune['Comune']['id'] == $user['Anagrafica']['comune_id']) echo " selected='selected' " ?>  ><? echo $comune['Comune']['descrizione'] ?></option>
								<? } ?> 
							</select> 
							<label style="display: inline;padding-left: 20px;" id="provincia_regione"  ></label>				
						</fieldset>
				    </div>
				  </div>
				</div>
			
			    <p>
					<?php echo $this->Acl->link("<i class='icon-plus'></i>", "/Users/add", array('class'=>'btn','escape'=>false));  ?>
					<button type="submit" class="btn btn-primary"><i class='icon-ok'></i></button>
					<?php echo $this->Acl->link("<i class='icon-trash'></i>",array("controller" => "Users", 'action' => 'delete', $user['User']['id']), array('data-confirm'=>'true','class'=>'btn','escape'=>false));  ?>
				</p>
			
				<?php unset($user); ?> 
			
	</div>
	</div>
</form>

<script>
	$(document).ready(function() {
		 $("#comune").select2({minimumInputLength: 3, placeholder: '<?php echo __("Seleziona un comune") ?>',allowClear: true}); 
		 $("#comune").change(function(){
		 	if($("#comune").val()=="")return;	
		 	 idprovincia=$('#comune :selected').data("idprovincia");
			 $.getJSON('<?php echo $this->webroot;?>Utils/regioneProvincia/'+idprovincia, function(data) {
		            $("#provincia_regione").html(data["Provincia"]["sigla"]+" - "+data["Regione"]["descrizione"]);
        	});
		 });
   });
</script>

